package com.sk.weichat.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.image.ImageInfo;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.android.flexbox.JustifyContent;
import com.sk.weichat.MyApplication;
import com.sk.weichat.R;
import com.sk.weichat.audio_x.VoiceManager;
import com.sk.weichat.bean.DynamicBean;
import com.sk.weichat.bean.SubjectItemBean;
import com.sk.weichat.bean.circle.PublicMessage;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.ui.mucfile.DownManager;
import com.sk.weichat.ui.mucfile.XfileUtils;
import com.sk.weichat.ui.mucfile.bean.DownBean;
import com.sk.weichat.ui.mucfile.bean.MucFileBean;
import com.sk.weichat.util.FrescoUtils;
import com.sk.weichat.util.MediaPlayerHelper;
import com.sk.weichat.util.ScreenUtil;
import com.sk.weichat.util.TimeUtils;
import com.sk.weichat.util.ViewPiexlUtil;
import com.sk.weichat.view.DynamicShortVideoControlView;
import com.sk.weichat.view.VoiceView;

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * @author lzs
 * @date 2019/10/22
 * Email:343067508@qq.com
 **/
public class DynamicMultiItemAdapter extends BaseMultiItemQuickAdapter<DynamicBean, BaseViewHolder> {
    public static final int IMAGE_X_MIN_SIZE = 180;
    public static final int IMAGE_X_MAX_SIZE = 226;

    public static final int IMAGE_Y_MIN_SIZE = 180;
    public static final int IMAGE_Y_MAX_SIZE = 306;

    public static final int video_max_height = 306; //dp
    public static final int video_max_width = 226; //dp

    RecyclerView.RecycledViewPool recycledViewPool;
    // WeakReference<Context> contextWeakReference;
    List<DynamicBean> data;

    public static final int voice_max_width = 248;
    public static final int voice_min_width = 150;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public DynamicMultiItemAdapter(List<DynamicBean> data) {
        super(data);
        //contextWeakReference = new WeakReference<>(context);
        this.data = data;
        //必须绑定type和layout的关系
        addItemType(DynamicBean.type_single_image, R.layout.item_dynamic_image_one);
        addItemType(DynamicBean.type_grid_image, R.layout.item_dynamic_image_grid);
        addItemType(DynamicBean.type_voice, R.layout.item_dynamic_voice);
        addItemType(DynamicBean.type_short_video, R.layout.item_dynamic_video);

        recycledViewPool = new RecyclerView.RecycledViewPool();
    }

    @Override
    protected void convert(BaseViewHolder holder, DynamicBean item) {
        holder.addOnClickListener(R.id.container, R.id.recyclerview, R.id.tv_location, R.id.recyclerview_topics);
        //
        SimpleDraweeView ivAvatar = holder.getView(R.id.iv_avatar);
        PublicMessage.Body body = item.getBody();
        //Log.e("lzs", "item.getUserId():" + AvatarHelper.getAvatarUrl(item.getUserId(), true));

        FrescoUtils.loadImage(ivAvatar, AvatarHelper.getAvatarUrl(item.getUserId(), true));
        //用户昵称
        holder.setText(R.id.tv_name, item.getNickName());
        //时间
        holder.setText(R.id.tv_time, TimeUtils.getFriendlyTimeDesc(holder.itemView.getContext(), item.getTime()));
        //内容
        TextView tvContent = holder.getView(R.id.tv_content);
        if (TextUtils.isEmpty(body.getText())) {
            tvContent.setVisibility(View.GONE);
            holder.getView(R.id.tv_more).setVisibility(View.GONE);
        } else {
            tvContent.setVisibility(View.VISIBLE);
            tvContent.setText(body.getText());
            TextView tvMore = holder.getView(R.id.tv_more);
            if (tvContent.getLayout() != null && tvContent.getLayout().getLineCount() == 4 && tvContent.getLayout().getEllipsisCount(3) > 0) {
                tvMore.setVisibility(View.VISIBLE);
            } else {
                tvMore.setVisibility(View.GONE);
            }
        }
        //地点
        if (TextUtils.isEmpty(item.getLocation())) {
            holder.getView(R.id.tv_location).setVisibility(View.GONE);
        } else {
            holder.getView(R.id.tv_location).setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_location, item.getLocation());
        }

        RecyclerView recyclerViewTopics = holder.getView(R.id.recyclerview_topics);
        //话题列表
        if (item.getTopicNames() != null && item.getTopicNames().size() > 0) {
            recyclerViewTopics.setVisibility(View.VISIBLE);
            //流式布局
            FlexboxLayoutManager layoutManager1 = new FlexboxLayoutManager(recyclerViewTopics.getContext());
            layoutManager1 = new FlexboxLayoutManager(recyclerViewTopics.getContext());
            layoutManager1.setFlexDirection(FlexDirection.ROW);
            layoutManager1.setJustifyContent(JustifyContent.FLEX_START);
            layoutManager1.setFlexWrap(FlexWrap.WRAP);
            recyclerViewTopics.setLayoutManager(layoutManager1);

            recyclerViewTopics.setAdapter(getTopicsAdapter(item.getTopicNames()));
        } else {
            recyclerViewTopics.setVisibility(View.GONE);
        }
        switch (holder.getItemViewType()) {
            case DynamicBean.type_single_image:
                convertSingleImage(holder, item);
                break;
            case DynamicBean.type_grid_image:
                convertGridImage(holder, item);
                break;

            case DynamicBean.type_voice:
                convertVoiceItem(holder, item);
                break;

            case DynamicBean.type_short_video:
                //视频
                convertVideoItem(holder, item);
                break;

        }
    }


    /**
     * 视频
     *
     * @param holder
     * @param item
     */
    private void convertVideoItem(BaseViewHolder holder, DynamicBean item) {
        PublicMessage.Body body = item.getBody();
        //设置视频的图片
        List<PublicMessage.Resource> images = body.getImages();
        SimpleDraweeView ivMask = holder.getView(R.id.iv_mask);
        if (images != null && images.size() > 0) {
            ivMask.setVisibility(View.VISIBLE);

            ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) ivMask.getLayoutParams();
            int height = item.getBody().getHeight();
            int width = item.getBody().getWidth();
            Log.e("lzs", "height:" + height + "  width:" + width);
            if (height > width) {
                int[] outSize = getVideoScaleSize(ivMask.getContext(), width, height);
                lp.width = outSize[0];
                lp.height = outSize[1];
            } else {
                int screenWidth = ScreenUtil.getScreenWidth(ivMask.getContext());
                screenWidth -= ViewPiexlUtil.dp2px(ivMask.getContext(), 32);
                // Log.e("lzs", "width:" + width + "  ivMask.getWidth()：" + ivMask.getWidth() + "  screenWidth:" + screenWidth);
                float scale = width * 1.0f / screenWidth;
                //Log.e("lzs", "scale:" + scale);
                lp.height = (int) (height / scale);
                lp.width = screenWidth;
            }
            ivMask.setLayoutParams(lp);
            FrescoUtils.loadImage(ivMask, images.get(0).getThumbnailUrl());
        } else {
            // ivMask.setVisibility(View.GONE);
        }
        List<PublicMessage.Resource> videos = body.getVideos();
        if (videos != null && videos.size() > 0) {

            //设置视频
            PublicMessage.Resource video = videos.get(0);
            Log.e("lzs", "url:" + video.getOriginalUrl());
            DynamicShortVideoControlView controlView = holder.getView(R.id.view_controll);
            if (item.isActive()) {
                controlView.setPauseVisibilty(View.GONE);
                controlView.hideLoading();
            } else {
                controlView.setPauseVisibilty(View.VISIBLE);
            }
            //设置声音图标的状态
            controlView.setVoiceIconState(video.isSilent());
        }
    }


    private int[] getVideoScaleSize(Context context, int originalWidth, int originalHeight) {
        int[] outSize = new int[2];
        if (originalWidth > originalHeight) {
            //横向视频

        } else {
            //纵向视频
            int maxH = dp2px(context, video_max_height);
            int maxW = dp2px(context, video_max_width);

            //原始高度大于最大高度，压缩宽高
            float scale = maxH * 1.0f / originalHeight;
            outSize[0] = (int) (originalWidth * scale);
            outSize[1] = maxH;
            //Log.e("lzs", "1111 maxH:" + maxH + "   maxW:" + maxW + "   originalWidth:" + originalWidth + "  originalHeight:" + originalHeight);
        }
        return outSize;
    }

    public static int dp2px(Context context, float dp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }

    /**
     * 语音
     *
     * @param holder
     * @param item
     */
    private void convertVoiceItem(BaseViewHolder holder, DynamicBean item) {
        PublicMessage.Body body = item.getBody();
        List<PublicMessage.Resource> audios = body.getAudios();
        VoiceView voiceView = holder.getView(R.id.view_voice);
        if (audios != null && audios.size() > 0) {
            PublicMessage.Resource audio = audios.get(0);

            voiceView.setVisibility(View.VISIBLE);
            voiceView.setMaxProgress((int) audio.getLength());
            voiceView.setTime(audio.getLength() + "''");
            ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) voiceView.getLayoutParams();
            if (audio.getLength() < 10) {
                //小于10秒没有进度条
                voiceView.setProgressBarVisibility(View.INVISIBLE);
                lp.width = ViewPiexlUtil.dp2px(voiceView.getContext(), voice_min_width);
            } else {
                voiceView.setProgressBarVisibility(View.VISIBLE);
                int dx = voice_max_width - voice_min_width;
                int width = (int) (audio.getLength() * 1.0f / 60 * dx + voice_min_width);
                lp.width = ViewPiexlUtil.dp2px(voiceView.getContext(), width);
            }
            voiceView.setLayoutParams(lp);
            voiceView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MucFileBean mucFileBean = new MucFileBean();
                    mucFileBean.setUrl(audios.get(0).getOriginalUrl());

                    String fileName = audio.getOriginalUrl().substring(audio.getOriginalUrl().lastIndexOf("/") + 1, audio.getOriginalUrl().length());
                    // 取出文件后缀
                    int start = audio.getOriginalUrl().lastIndexOf(".");
                    String suffix = start > -1 ? audio.getOriginalUrl().substring(start + 1).toLowerCase() : "";

                    int fileType = XfileUtils.getFileType(suffix);
                    mucFileBean.setUrl(audio.getOriginalUrl());
                    mucFileBean.setName(fileName);
                    mucFileBean.setSize(audio.getSize());

                    mucFileBean.setType(fileType);
                    File file2 = new File(DownManager.instance().getFileDir() + File.separator + fileName);
                    mucFileBean.setFilePath(file2.getAbsolutePath());
                    DownBean info = DownManager.instance().getDownloadState(mucFileBean);
                    int state = info.state;
                    if (state != DownManager.STATE_DOWNLOADED && state != DownManager.STATE_DOWNLOADING) {
                        DownManager.instance().addObserver(new DownManager.DownLoadObserver() {
                            @Override
                            public void onDownLoadInfoChange(DownBean info) {
                                //下载成功播放
                                if (info.state == DownManager.STATE_DOWNLOADED) {
                                    if (currentVoiceView == null || currentVoiceView != voiceView || VoiceManager.instance().getState() == VoiceManager.STATE_FINISH) {
                                        flag = false;
                                        //停止其他的语音
                                        if (currentVoiceView != null) {
                                            currentVoiceView.stopAnim();
                                            currentVoiceView.updateProgress(0);
                                            VoiceManager.instance().stop();
                                        }
                                        currentVoiceView = voiceView;
                                        playVoice(file2.getAbsolutePath());
                                    } else if (currentVoiceView == voiceView) {
                                        currentVoiceView.stopAnim();
                                        currentVoiceView.updateProgress(0);
                                        VoiceManager.instance().stop();
                                    }
                                    DownManager.instance().deleteObserver(this);
                                }
                            }
                        });
                        DownManager.instance().download(mucFileBean);
                    } else if (state == DownManager.STATE_DOWNLOADED) {
                        if (currentVoiceView == null || currentVoiceView != voiceView || VoiceManager.instance().getState() == VoiceManager.STATE_FINISH) {
                            flag = false;
                            //停止其他的语音
                            if (currentVoiceView != null) {
                                currentVoiceView.stopAnim();
                                currentVoiceView.updateProgress(0);
                                VoiceManager.instance().stop();
                            }
                            currentVoiceView = voiceView;
                            playVoice(file2.getAbsolutePath());
                        } else if (currentVoiceView == voiceView) {
                            currentVoiceView.stopAnim();
                            currentVoiceView.updateProgress(0);
                            VoiceManager.instance().stop();
                        }
                    }
                }
            });
        } else {
            voiceView.setVisibility(View.GONE);
        }
    }

    private VoiceView currentVoiceView;

    private void playVoice(String path) {
        if (TextUtils.isEmpty(path)) {
            return;
        }
        if (VoiceManager.instance().getState() != VoiceManager.STATE_PLAY) {
            if (currentVoiceView != null) {
                currentVoiceView.startAnim();
            }
            flag = true;
            timer();
            VoiceManager.instance().play(path);
            VoiceManager.instance().addVoicePlayListener(new VoiceManager.VoicePlayListener() {
                @Override
                public void onFinishPlay(String path) {
                    if (null != currentVoiceView) {
                        currentVoiceView.stopAnim();
                    }
                    flag = false;
                }

                @Override
                public void onStopPlay(String path) {
                    if (null != currentVoiceView) {
                        currentVoiceView.stopAnim();
                    }
                    flag = false;
                }

                @Override
                public void onErrorPlay() {
                    if (null != currentVoiceView) {
                        currentVoiceView.stopAnim();
                    }
                    flag = false;
                }
            });
        } else if (VoiceManager.instance().getState() == VoiceManager.STATE_PLAY) {
            flag = false;
            VoiceManager.instance().pause();
            currentVoiceView.stopAnim();
        }
    }

    private boolean flag = false;

    Disposable dispose = null;

    private void timer() {
        if (dispose == null) {
            dispose = Observable.interval(200, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Long>() {
                @Override
                public void accept(Long aLong) throws Exception {
                    if (flag) {
                        int current = VoiceManager.instance().getCurrentPosition();
                        int max = VoiceManager.instance().getDuration();
                        currentVoiceView.setMaxProgress(max);
                        currentVoiceView.updateProgress(current);
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    dispose.dispose();
                }
            });
        }
    }

    /**
     * 网格多图
     */
    private void convertGridImage(BaseViewHolder holder, DynamicBean item) {
        //
        RecyclerView recyclerView = holder.getView(R.id.recyclerview);
//        GridDivider divider = new GridDivider(recyclerView.getContext(), ViewPiexlUtil.dp2px(recyclerView.getContext(), 8), 0, false, false,recyclerView.getResources().getColor(R.color.white) );
//        recyclerView.addItemDecoration(divider);
        //四个数据的时候排列顺序有变化每行只排两个,第3个使用空数据占位
        List<PublicMessage.Resource> resouces = item.getBody().getImages();
        List<PublicMessage.Resource> imgs = new ArrayList<>();
        if (resouces.size() == 4) {
            imgs.add(resouces.get(0));
            imgs.add(resouces.get(1));
            //空数据
            PublicMessage.Resource resource = new PublicMessage.Resource();
            resource.setOriginalUrl("");
            imgs.add(resource);
            imgs.add(resouces.get(2));
            imgs.add(resouces.get(3));
        }
        GridLayoutManager layoutManager = null;
        if (resouces.size() == 2) {
            layoutManager = new GridLayoutManager(recyclerView.getContext(), 2);
        } else {
            layoutManager = new GridLayoutManager(recyclerView.getContext(), 3);
        }
        layoutManager.setInitialPrefetchItemCount(9);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(null);
        BaseQuickAdapter<PublicMessage.Resource, BaseViewHolder> adapter = new BaseQuickAdapter<PublicMessage.Resource, BaseViewHolder>(R.layout.item_dynamic_image, resouces.size() == 4 ? imgs : resouces) {
            @Override
            protected void convert(BaseViewHolder holder1, PublicMessage.Resource item) {
                //Log.e("lzs", "convert:" + item.getOriginalUrl());
                if (!TextUtils.isEmpty(item.getThumbnailUrl())) {
                    FrescoUtils.loadImage(holder1.getView(R.id.iv_image), item.getThumbnailUrl());
                } else {
                    FrescoUtils.setImageRes(holder1.getView(R.id.iv_image), R.drawable.shape_corner_8dp_solid_white);
                }
            }
        };
        recyclerView.setRecycledViewPool(recycledViewPool);
        recyclerView.setAdapter(adapter);
    }

    /**
     * 单图
     *
     * @param holder
     * @param item
     */
    private void convertSingleImage(BaseViewHolder holder, DynamicBean item) {
        //
        PublicMessage.Body body = item.getBody();
        SimpleDraweeView ivImage = holder.getView(R.id.iv_image);
        //图片
        if (body.getImages() != null && body.getImages().size() > 0 && !TextUtils.isEmpty(body.getImages().get(0).getOriginalUrl())) {
            ivImage.setVisibility(View.VISIBLE);
            FrescoUtils.loadImageControllerListener(ivImage, body.getImages().get(0).getThumbnailUrl(), new BaseControllerListener<ImageInfo>() {
                @Override
                public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) {
                    if (imageInfo == null) {
                        return;
                    }
                    //重新设置图片的高度宽度
                    int h = imageInfo.getHeight();
                    int w = imageInfo.getWidth();
                    //Log.e("lzs", "h:" + h + "  w:" + w);
                    float[] outSize = getScaleSize(ivImage.getContext(), w, h);
                    ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) ivImage.getLayoutParams();
                    lp.height = (int) outSize[1];
                    lp.width = (int) outSize[0];
                    ivImage.setLayoutParams(lp);
                }

                @Override
                public void onIntermediateImageSet(String id, ImageInfo imageInfo) {
                    Log.e("lzs", "Intermediate image received");
                }

                @Override
                public void onFailure(String id, Throwable throwable) {
                    throwable.printStackTrace();
                    Log.e("lzs", "onFailure:" + throwable.getMessage());
                }
            });

        } else {
            ivImage.setVisibility(View.GONE);
        }
    }

    private float[] getScaleSize(Context context, float originalW, float originalH) {
        float[] outSize = new float[2];
        int minX = ViewPiexlUtil.dp2px(context, IMAGE_X_MIN_SIZE);
        int minY = ViewPiexlUtil.dp2px(context, IMAGE_Y_MIN_SIZE);
        int maxX = ViewPiexlUtil.dp2px(context, IMAGE_X_MAX_SIZE);
        int maxY = ViewPiexlUtil.dp2px(context, IMAGE_Y_MAX_SIZE);
        // Log.e("lzs", "minX:" + minX + " minY:" + minY + "   originalW:" + originalW + "  originalH:" + originalH);
        if (originalW > originalH) {
            //横向图
            if (originalW < minX) {
                outSize[0] = maxX;
                outSize[1] = originalH * 1.0f / originalW * maxX;
            } else {
                float scale = originalH * 1.0f / originalW;
                if (scale < 0.3) {
                    //图片特别宽，高度设置为最大高度的一半
                    outSize[1] = maxY / 2;
                } else {
                    //限制高度不能超过最大高度
                    outSize[1] = Math.min((int) (scale * maxY), maxY);
                }
                outSize[0] = maxX;
            }
        } else if (originalW == originalH) {
            outSize[0] = maxX;
            outSize[1] = maxX;
        } else {
            //竖向图
            if (originalH < minY) {
//                if (originalW > min) {
                //如果原始宽度大于最大宽度，需要缩放
                outSize[0] = minY;
                float scale = originalW * 1.0f / minY;
                Log.e("lzs", "originalH / scale:" + originalH / scale);
                outSize[1] = Math.min(originalH / scale, maxY);
//                } else {
//                    outSize[0] = originalW;
//                    outSize[1] = originalH;
//                }
            } else {
                float scale = originalW * 1.0f / originalH;
                if (scale < 0.3) {
                    //长宽比例较大,图片特别长，宽度设置为最大宽度的一半
                    outSize[0] = maxY / 2;
                } else {
                    //取原图按比例缩放后的值和最大宽度中较小者
                    outSize[0] = Math.min((int) (scale * maxY), maxY);
                }
                outSize[1] = maxY;
            }
        }
        return outSize;
    }

    /**
     * 话题适配器
     *
     * @return
     */
    private BaseQuickAdapter<String, BaseViewHolder> getTopicsAdapter(List<String> topics) {
        BaseQuickAdapter<String, BaseViewHolder> adapter = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_dynamic_topic, topics) {
            @Override
            protected void convert(BaseViewHolder helper, String item) {
                helper.addOnClickListener(R.id.tv_name);
                helper.setText(R.id.tv_name, "#" + item + "#");
            }
        };
        adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (view.getId() == R.id.tv_name) {
                    if (onTopicClickListener != null) {
                        onTopicClickListener.onTopicClick(topics.get(position));
                    }
                }
            }
        });

        return adapter;
    }


    public void onPause() {
        if (VoiceManager.instance().getState() == VoiceManager.STATE_PLAY) {
            if (currentVoiceView != null) {
                currentVoiceView.stopAnim();
                currentVoiceView.updateProgress(0);
            }
            VoiceManager.instance().stop();
        }
    }

    private OnTopicClickListener onTopicClickListener;

    public void setOnTopicClickListener(OnTopicClickListener onTopicClickListener) {
        this.onTopicClickListener = onTopicClickListener;
    }

    public interface OnTopicClickListener {
        void onTopicClick(String topicName);
    }

//    @Override
//    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position, @NonNull List<Object> payloads) {
//        super.onBindViewHolder(holder, position, payloads);
//        if (payloads.isEmpty()) {
//            onBindViewHolder(holder, position);
//        } else {
//            SimpleDraweeView ivMask = holder.getView(R.id.iv_mask);
//            List<PublicMessage.Resource> images = data.get(position).getBody().getImages();
//            if (ivMask != null && images != null && images.size() > 0) {
//                FrescoUtils.loadImageControllerListener(ivMask, images.get(0).getOriginalUrl(), new BaseControllerListener<ImageInfo>() {
//                    @Override
//                    public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
//                        super.onFinalImageSet(id, imageInfo, animatable);
//                        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) ivMask.getLayoutParams();
//                        lp.height = imageInfo.getHeight();
//                        lp.width = imageInfo.getWidth();
//                        Log.e("size", "lp.height:" + lp.height + "  lp.width:" + lp.width);
//                        ivMask.setLayoutParams(lp);
//                    }
//                });
//            }
//        }
//    }


}
